﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// PurviewManageBLL 的摘要说明
/// </summary>
public class PurviewManageBLL
{
    DataBase data = new DataBase();
    public PurviewManageBLL()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    #region 添加--管理员权限
    /// <summary>
    /// 添加--管理员权限
    /// </summary>
    /// <param name="purviewmanage"></param>
    /// <returns></returns>
    public int AddPurview(PurviewManage purviewmanage)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.VarChar, 50, purviewmanage.ID ),
            data.MakeInParam("@sysset",  SqlDbType.Bit, 1,purviewmanage.SysSet ),
            data.MakeInParam("@readset",  SqlDbType.Bit, 1, purviewmanage.ReadSet ),
            data.MakeInParam("@bookset",  SqlDbType.Bit, 1, purviewmanage.BookSet ),
            data.MakeInParam("@borrowback",  SqlDbType.Bit, 1, purviewmanage.BorrowBack ),
            data.MakeInParam("@sysquery",  SqlDbType.Bit, 1, purviewmanage.SysQuery ),
            };
        return (data.RunProc("INSERT INTO tb_purview (id,sysset,readset,bookset,borrowback,sysquery) "
            + "VALUES (@id,@sysset,@readset,@bookset,@borrowback,@sysquery)", prams));
    }
    #endregion

    #region 修改--管理员权限
    /// <summary>
    /// 修改--管理员权限
    /// </summary>
    /// <param name="purviewmanage"></param>
    /// <returns></returns>
    public int UpdatePurview(PurviewManage purviewmanage)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.VarChar, 50, purviewmanage.ID ),
            data.MakeInParam("@sysset",  SqlDbType.Bit, 1,purviewmanage.SysSet ),
            data.MakeInParam("@readset",  SqlDbType.Bit, 1, purviewmanage.ReadSet ),
            data.MakeInParam("@bookset",  SqlDbType.Bit, 1, purviewmanage.BookSet ),
            data.MakeInParam("@borrowback",  SqlDbType.Bit, 1, purviewmanage.BorrowBack ),
            data.MakeInParam("@sysquery",  SqlDbType.Bit, 1, purviewmanage.SysQuery ),
            };
        return (data.RunProc("update tb_purview set sysset=@sysset,readset=@readset,bookset=@bookset,"
            + "borrowback=@borrowback,sysquery=@sysquery where id=@id", prams));
    }
    #endregion

    #region 删除--管理员权限
    /// <summary>
    /// 删除--管理员权限
    /// </summary>
    /// <param name="purviewmanage"></param>
    /// <returns></returns>
    public int DeletePurview(PurviewManage purviewmanage)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.VarChar, 50, purviewmanage.ID ),
            };
        return (data.RunProc("delete from tb_purview where id=@id", prams));
    }
    #endregion

    #region 查询--管理员权限
    /// <summary>
    /// 根据--管理员编号--得到管理员权限
    /// </summary>
    /// <param name="purviewmanage"></param>
    /// <param name="tbName"></param>
    /// <returns></returns>
    public DataSet FindPurviewByID(PurviewManage purviewmanage, string tbName)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.VarChar, 50, purviewmanage.ID +"%"),
            };
        return (data.RunProcReturn("select * from tb_purview where id like @id", prams, tbName));
    }
    /// <summary>
    /// 得到所有--管理员权限
    /// </summary>
    /// <param name="tbName"></param>
    /// <returns></returns>
    public DataSet GetAllPurview(string tbName)
    {
        return (data.RunProcReturn("select * from tb_purview ORDER BY id", tbName));
    }
    /// <summary>
    /// 得到所有--管理员权限(根据名字)
    /// </summary>
    /// <param name="tbName"></param>
    /// <returns></returns>
    public DataSet GetAllPurviewByName(string tbName)
    {
        return (data.RunProcReturn("select * from view_AdminPurview ORDER BY id", tbName));
    }
    #endregion
}